package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.entity.Cmservices;
import com.dingreading.cloud.admin.entity.Subjects;
import com.dingreading.cloud.admin.service.CmservicesService;
import com.dingreading.cloud.admin.service.SubjectLessonService;
import com.dingreading.cloud.admin.service.SubjectsService;
import com.dingreading.cloud.common.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/system/subjects/v2")
@Api(tags = "总部-双思学科修改")
public class SsSubjectController {

    @Resource
    private SubjectsService subjectsService;
    @Resource
    private SubjectLessonService subjectLessonService;
    @Resource
    private CmservicesService cmservicesService;

    long mainId = 353;


    @ApiOperation(value = "修改双思会员订单服务")
    @PostMapping(value = "/updateSsCmservice")
    public R<Object> updateSsCmservice() {
        String mainSubjectUid = "8744a0855e4e4dd4860feabf29628a64";
        List<Cmservices> list = cmservicesService.listByMainSubjectUid(mainSubjectUid);
        if (CollectionUtils.isNotEmpty(list)) {
            for (Cmservices cmservices : list) {
                String subjectName = cmservices.getSubjectName();
                String stageName = cmservices.getStageName();

                Subjects subject = subjectsService.getByMainIdAndNameAndLevelIndex(mainId, stageName, 1);
                Subjects stage = subjectsService.getByParentIdAndSubjectName(subject.getId(), subjectName, 2);

                cmservicesService.updateSubject(cmservices.getUid(), subject.getUid(), subject.getSubjectName(), stage.getUid(), stage.getSubjectName());
            }
        }
        return R.ok();
    }

}
